package com.qibo.order;

import android.os.Bundle;
import android.view.View;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.qibo.baselib.adapter.BaseAdapter;
import com.qibo.baselib.base.BaseFragment;
import com.qibo.baselib.utils.XRecyclerViewHelper;
import com.qibo.order.adapter.OrderListAdapter;
import com.qibo.order.bean.OrderBean;

import java.util.ArrayList;
import java.util.List;

public class OrderListFragment extends BaseFragment implements XRecyclerView.LoadingListener{

    OrderListAdapter mAdapter;
    private List<OrderBean> mDatas = new ArrayList<OrderBean>();
    XRecyclerView mRecyclerView;
    @Override
    protected int getInflaterLayoutId() {
        return R.layout.ordermodule_frag_orderlist;
    }
    public static OrderListFragment newInstance(int type) {
        Bundle args = new Bundle();
        OrderListFragment fragment = new OrderListFragment();
        args.putInt("type", type);
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    protected void initView(View view) {
        mRecyclerView = view.findViewById(R.id.orderlist_recly_view);
        XRecyclerViewHelper.init().setLinearLayout(mContext, mRecyclerView);
        mRecyclerView.setLoadingListener(this);
    }

    @Override
    protected void initAction() {

    }

    @Override
    protected void initData() {

            for (int j = 0; j<10; j++){
                OrderBean orderBean = new OrderBean();
                orderBean.setTitile("标题"+j);
                mDatas.add(orderBean);
            }
        mAdapter = new OrderListAdapter(mContext,mDatas);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                switchActivity(OrderListDetailsActivity.class);
            }
        });
    }

    @Override
    public void onRefresh() {
        mRecyclerView.refreshComplete();
    }

    @Override
    public void onLoadMore() {
        mRecyclerView.loadMoreComplete();
    }
}
